<!doctype html>
<html><head>
</head><body>
<p>WebViewJavascriptBridgeTests - echo.html</p>
<script>
	function setupWebViewJavascriptBridge(callback) {
		var bridge=window.WebViewJavascriptBridge||window.WKWebViewJavascriptBridge
		if (bridge) { return callback(bridge); }
		var callbacks=window.WVJBCallbacks||window.WKWVJBCallbacks
		if (callbacks) { return callbacks.push(callback); }
		window.WVJBCallbacks=window.WKWVJBCallbacks = [callback];
		if(window.WKWebViewJavascriptBridge){
		  window.webkit.messageHandlers.iOS_Native_InjectJavascript.postMessage(null)
		}else{
			var WVJBIframe = document.createElement('iframe');
			WVJBIframe.style.display = 'none';
			WVJBIframe.src = 'https://__bridge_loaded__';
			document.documentElement.appendChild(WVJBIframe);
			setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
		}
	}

	setupWebViewJavascriptBridge(function(bridge) {
		bridge.registerHandler('echoHandler', function(data, responseCallback) {
			responseCallback(data)
		})
		bridge.registerHandler('jsRcvResponseTest', function(data, responseCallback) {
			bridge.callHandler('javaEchoToJs', { foo:'bar' }, function(response) {
				if (response && response.foo == 'bar') {
					responseCallback("Response from JS")
				} else {
					responseCallback("Failed")
				}
			})
		})
		//bridge.hasNativeMethod('javaEchoToJs',function(b){
		//   alert(b===true)
		//})
	})
	</script>
</body></html>
